<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" type="text/css" href="/gaspider/easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="/gaspider/easyui/themes/icon.css">
	<script type="text/javascript" src="/gaspider/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="/gaspider/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="/gaspider/easyui/locale/easyui-lang-zh_CN.js"></script>
	<style>
		*{
			margin:0;
			padding:0;
		}
		.setting{
			background-color:#F8F8F8;
			width:100%;
			//height:7%;
			padding:5px 0 5px 0;
		}
		.content{
			//border:2px solid green;
			height:93%;
			
			
		}
		body,html{
			//border:2px solid black;
			height:100%;
			//width:100%;
			font-family: "Microsoft YaHei",华文细黑,微软雅黑,文鼎简报宋;
			font-size:7px;
		}
		
	</style> 

</head>
<body>
		<div class="setting">
				&nbsp;&nbsp;&nbsp;&nbsp;
				启动时间：<input type="text" id="starttime">
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				间隔时间：<input type="text" id="interval">
				&nbsp;&nbsp;
    			<a href="#" class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="save()">保存</a>
				
		</div>
		<div class="content">
			<table id="dg"></table>
		</div>
		
	
</body>
</html>
<script>
$(function(){
	function openWindow(url){
		window.parent.$('#win').window({    
		    width:900,    
		    height:500, 
		    content:'<div style="overflow:hidden;width:100%;height:100%;"><iframe src="'+url+'" frameborder="0" width="100%" height="100%"><iframe></div>',
		    modal:true   
		});
	}
	$("#dg").datagrid({    
	    url:'/gaspider/service/getdata.do', 
	    fit:true,
	    pagination:true,
	    idField:"id",
	    fitColumns:true,
	    toolbar: [{
			iconCls: 'icon-add',
			text:'启动',
			handler: function(){
				var datat = $('#dg').datagrid('getChecked');
				for(var m=0;m<datat.length;m++){
					delete datat[m].urlfilter
					delete datat[m].titlefilter
					delete datat[m].contentfilter
					delete datat[m].releasedatefilter
				}
				var jsonform = {
					"servicestart":datat	
				}
				
				if(datat.length==0){
					$.messager.show({
						title:'消息',
						msg:'请先选择至少一行。',
						timeout:1000,
						showType:'slide'
					});
				}else{
					$.ajax({
						url:'/gaspider/service/start.do',
						type: "post",
						data: jsonform,
						success:function(result){
							if(result.success){
								$.messager.show({
									title:'消息',
									msg:'更新成功。',
									timeout:1000,
									showType:'slide'
								});
							}else{
								$.messager.show({
									title:'消息',
									msg:'更新失败。',
									timeout:1000,
									showType:'slide'
								});
							}
							$('#dg').datagrid('reload');
							$('#dg').datagrid('clearChecked');
						}
					});
				}
				
			}
		},'-',{
			iconCls: 'icon-edit',
			text:'停止',
			handler: function(){
				var datat = $('#dg').datagrid('getChecked');
				for(var m=0;m<datat.length;m++){
					delete datat[m].urlfilter
					delete datat[m].titlefilter
					delete datat[m].contentfilter
					delete datat[m].releasedatefilter
				}
				var jsonform = {
					"servicestop":datat	
				}
				
				if(datat.length==0){
					$.messager.show({
						title:'消息',
						msg:'请先选择至少一行。',
						timeout:1000,
						showType:'slide'
					});
				}else{
					$.ajax({
						url:'/gaspider/service/stop.do',
						type: "post",
						data: jsonform,
						success:function(result){
							if(result.success){
								$.messager.show({
									title:'消息',
									msg:'更新成功。',
									timeout:1000,
									showType:'slide'
								});
							}else{
								$.messager.show({
									title:'消息',
									msg:'更新失败。',
									timeout:1000,
									showType:'slide'
								});
							}
							$('#dg').datagrid('reload');
							$('#dg').datagrid('clearChecked');
						}
					});
				}
				
			}
		}],
		 columns:[[ {
 			field:'t',
 			checkbox:true,
 		}, {
				field : 'id',
				title : 'id',
				hidden:true,
			}, {
				field : 'articletype',
				title : '文章类型',
				width:30,
				align:'center'
			}, {
				field : 'websitename',
				title : '网站名称',
				width:30,
				align:'center'
			}, {
				field : 'entryurl',
				title : '入口地址',
				width:30,
				align:'center'
			}, {
				field : 'taskstate',
				title : '任务状态',
				width:30,
				align:'center'
			} ]]
	});
	$('#starttime').combobox({    
	    textField:'id',    
	    valueField:'text',
		data: [{
			id: '早上4:00',
			text: '0 0 4 ',
			//selected:true
		},{
			id: '中午12:00',
			text: '0 0 12 '
		},{
			id: '晚上20:00',
			text: '0 0 20 '
		}]
	}); 
	$('#interval').combobox({    
	    textField:'id',    
	    valueField:'text',
		data: [{
			id: '每周一',
			text: '? * 2',
			//selected:true
		},{
			id: '每周三',
			text: '? * 4'
		},{
			id: '每周六',
			text: '? * 7'
		},{
			id: '每月15日',
			text: '15 * ?'
		}]
	}); 
	$.ajax({
		url:'/gaspider/service/service.do',
		type: "post",
		success:function(result){
			if(result.success){
				
				$('#starttime').combobox('select',result.start);
				$('#interval').combobox('select',result.interval);
				
			}
		}
	});
});
function save(){
	var start = $('#starttime').combobox('getValue');
	var interval = $('#interval').combobox('getValue');
	$.ajax({
		url:'/gaspider/service/save.do',
		type: "post",
		data:'start='+start+'&interval='+interval,
		success:function(result){
			if(result.success){
				$.messager.show({
					title:'消息',
					msg:'保存成功。',
					timeout:1000,
					showType:'slide'
				});
			}else{
				$.messager.show({
					title:'消息',
					msg:'保存失败。',
					timeout:1000,
					showType:'slide'
				});
			}
		}
	});
}
</script>